package com.sky.mapper;

import com.sky.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;

@Mapper
public interface UserMapper {
    /**
     * 通过openid查询用户
     * @param openid
     */
    @Select("select * from user where openid = #{openid}")
    User getByopenid(String openid);

    /**
     * 插入新用户
     * @param user
     */
    void insert(User user);

    /**
     * 根据用户id查询用户
     * @param userId
     * @return
     */
    @Select("select * from user where id=#{userId}")
    User getById(Long userId);

    /**
     * 根据时间范围查询总用户数
     * @param begin
     * @param end
     * @return
     */
    @Select("select count(id) from user where create_time <= #{end}")
    Integer getTotalUserByTimeRange(LocalDateTime begin, LocalDateTime end);

    /**
     * 根据时间范围查询新增用户数
     * @param begin
     * @param end
     * @return
     */
    @Select("select count(id) from user where create_time between #{begin} and #{end}")
    Integer getNewUserByTimeRange(LocalDateTime begin, LocalDateTime end);
}
